#!/usr/bin/env python3
"""
发送命令到STM32设备
"""

import serial
import sys
import time

DEVICE = "/dev/ttyACM0"
BAUDRATE = 115200

if len(sys.argv) < 2:
    print("用法: ./send_cmd.py <命令>")
    print("例如: ./send_cmd.py help")
    sys.exit(1)

cmd = " ".join(sys.argv[1:])

try:
    ser = serial.Serial(DEVICE, BAUDRATE, timeout=0.5)
    print(f"发送命令: {cmd}")
    ser.write((cmd + '\n').encode('utf-8'))
    ser.flush()
    ser.close()
    print("命令已发送")
except Exception as e:
    print(f"错误: {e}")
    sys.exit(1)

